#include "global.h"

struct mapgen_gamelevel vizmap;

static unsigned char hasgift[300];

unsigned char viz_has_gift(int r)
{
	return hasgift[r];
}

unsigned char viz_get_tile(int x, int y)
{
	if (x < 0) return 17;
	if (y < 0) return 17;
	if (x >= vizmap.w) return 17;
	if (y >= vizmap.h) return 17;

	return vizmap.m[vizmap.w*y+x];
}

int viz_get_room(int x, int y)
{
	if (x < 0) return -1;
	if (y < 0) return -1;
	if (x >= vizmap.w) return -1;
	if (y >= vizmap.h) return -1;

	return vizmap.r[vizmap.w*y+x];

}

void viz_convert(int w, int h, unsigned char *tiles, int *rooms)
{
	vizmap.r = malloc(w*h*sizeof(int));
	vizmap.m = malloc(w*h*sizeof(unsigned char));

	memcpy(vizmap.r, rooms, w*h*sizeof(int));
	memcpy(vizmap.m, tiles, w*h*sizeof(unsigned char));
	vizmap.w = w;
	vizmap.h = h;

}

void viz_entry_at(roominfo *r)
{
	(void) r;
}

void viz_exit_at(roominfo *r)
{
	(void) r;
}

void viz_place_enemies(roominfo *r)
{
	(void) r;
}

void viz_gift(roominfo *r)
{
	printf("Adding gift in room %d\n", (r-&rooms[0]));
	hasgift[r-&rooms[0]] = 1;
}

void viz_teleporter(roominfo *from, roominfo *to)
{
	(void) from;
	(void) to;
}

void viz_init_hooks()
{
	dungeonmap_convert = viz_convert;
	dungeonmap_entry_at = viz_entry_at;
	dungeonmap_exit_at = viz_exit_at;
	dungeonmap_place_enemies = viz_place_enemies;
	dungeonmap_gift = viz_gift;
}

